package com.lwlk.demo.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Properties;

@ConfigurationProperties(prefix = "spring.datasource.druid")
@Setter
@Getter
public class DruidDataSourceProperties {

    private String initialSize;

    private String minIdle;

    private String maxActive;

    private String maxWait;

    private String timeBetweenEvictionRunsMillis;

    private String minEvictableIdleTimeMillis;

    private String validationQuery;

    private String testWhileIdle;

    private String testOnBorrow;

    private String testOnReturn;

    private String poolPreparedStatements;

    private String maxPoolPreparedStatementPerConnectionSize;

    public Properties toProperties() {

        Properties properties = new Properties();

        properties.setProperty("druid.initialSize", initialSize);

        properties.setProperty("druid.minIdle", minIdle);

        properties.setProperty("druid.maxActive", maxActive);

        properties.setProperty("druid.maxWait", maxWait);

        properties.setProperty("druid.timeBetweenEvictionRunsMillis", timeBetweenEvictionRunsMillis);

        properties.setProperty("druid.minEvictableIdleTimeMillis", minEvictableIdleTimeMillis);

        properties.setProperty("druid.validationQuery", validationQuery);

        properties.setProperty("druid.testWhileIdle", testWhileIdle);

        properties.setProperty("druid.testOnBorrow", testOnBorrow);

        properties.setProperty("druid.testOnReturn", testOnReturn);

        properties.setProperty("druid.poolPreparedStatements", poolPreparedStatements);

        properties.setProperty("druid.maxPoolPreparedStatementPerConnectionSize", maxPoolPreparedStatementPerConnectionSize);

        return properties;
    }
}
